#ifndef SYS_H
#define SYS_H

#include "Common_Types.h"
#if defined(linux) || defined(__CYGWIN__)
	#include <time.h>
	#include <sys/timex.h>
#elif defined(__APPLE__)
	#include <sys/time.h>
#endif
#include <syslog.h>

//#define DEBUG_MESSAGE

#define PERROR(x, ...) message(LOG_ERR, x ": %m\n", ##__VA_ARGS__)
#define NOTIFY(x, ...) message(LOG_NOTICE, x, ##__VA_ARGS__)
#define INFO(x, ...)   message(LOG_INFO, x, ##__VA_ARGS__)

#ifdef DEBUG_MESSAGE
	#define DBG(x, ...) message(LOG_DEBUG, x, ##__VA_ARGS__)
#else
	#define DBG(x, ...)
#endif
/*
typedef enum
{
	LOG_EMERG,
	LOG_ALERT,
	LOG_CRIT,
	LOG_ERR,
	LOG_WARNING,
	LOG_NOTICE,
	LOG_INFO,
	LOG_DEBUG
} LOG_TYPES_ENUM;
*/
typedef enum
{
	REQRT_INTERVAL_TIMER =0,
	IL2CLRT_INTERVAL_TIMER,
	INTERVAL_TIMER_SIZE
} INTERVAL_TIMER_TYPE_ENUM;
typedef struct {
  U32 seconds;
  U32 nanoseconds;

} TimeInternal;

typedef struct {
  U32  interval;
  U32  left;
  BOOL expire;
} IntervalTimer;

#ifdef __cplusplus
	extern "C" {
		TimeInternal subtractTime(const TimeInternal* t1, const TimeInternal* t2);
		TimeInternal addTime(const TimeInternal* t1, const TimeInternal* t2);
		BOOL greaterThan(const TimeInternal* t1, const TimeInternal* t2);
		BOOL nanoSleep(TimeInternal * t);
		void getTime(TimeInternal * time);
		void message(int priority, const char *format, ...);

		void catch_alarm(int sig);
		void initTimer(void);
		void timerUpdate(IntervalTimer * itimer);
		void timerStop(U16 index, IntervalTimer * itimer);
		void timerStart(U16 index, U16 interval, IntervalTimer * itimer);
		BOOL timerExpired(U16 index, IntervalTimer * itimer);
	}
#endif

#endif
